package com.icoolkj.ms.auth.feign;

import com.icoolkj.ms.api.auth.bo.UserInfoInTokenBO;
import com.icoolkj.ms.api.auth.feign.TokenFeignClient;
import com.icoolkj.ms.auth.manager.TokenManager;
import com.icoolkj.ms.common.core.constant.Auth;
import com.icoolkj.ms.common.core.response.ServerResponseEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author icoolkj
 * @version 1.0
 * @description
 * @createDate 2025/02/03 22:56
 */
@RestController
public class TokenFeignController implements TokenFeignClient {

	private static final Logger logger = LoggerFactory.getLogger(TokenFeignController.class);

	@Autowired
	private TokenManager tokenManager;

	@Override
	@GetMapping(value = Auth.CHECK_TOKEN_URI)
	public ServerResponseEntity<UserInfoInTokenBO> checkToken(@RequestParam("accessToken") String accessToken) {
		ServerResponseEntity<UserInfoInTokenBO> userInfoByAccessTokenResponse = tokenManager.getUserInfoByAccessToken(accessToken, true);
		if (!userInfoByAccessTokenResponse.isSuccess()) {
			return ServerResponseEntity.transform(userInfoByAccessTokenResponse);
		}
		return ServerResponseEntity.success(userInfoByAccessTokenResponse.getData());
	}

}
